#
# Copyright (C) 2004-2011 Red Hat, Inc.  All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

MAINTAINERCLEANFILES	= Makefile.in

SUBDIRS			= utils

TARGET			= fs.sh

RESOURCES		= service.sh ip.sh nfsclient.sh nfsexport.sh \
			  script.sh netfs.sh clusterfs.sh smb.sh \
			  apache.sh openldap.sh samba.sh mysql.sh \
			  postgres-8.sh tomcat-5.sh lvm.sh \
			  vm.sh SAPInstance SAPDatabase named.sh db2.sh \
			  ASEHAagent.sh drbd.sh nfsserver.sh \
			  tomcat-6.sh orainstance.sh oralistener.sh oracledb.sh \
			  bind-mount.sh oradg.sh

METADATA		= apache.metadata openldap.metadata samba.metadata \
			  mysql.metadata postgres-8.metadata \
			  tomcat-5.metadata named.metadata lvm.metadata \
			  drbd.metadata tomcat-6.metadata \
			  orainstance.metadata oralistener.metadata \
			  oradg.metadata

HELPERS			= ocf-shellfuncs svclib_nfslock \
			  lvm_by_lv.sh lvm_by_vg.sh

DTD			= ra-api-1-modified.dtd

XSL			= ra2man.xsl ra2ref.xsl ra2rng.xsl

RESRNG			= resources.rng.head resources.rng.mid resources.rng.tail

EXTRA_DIST		= $(TARGET:=.in) \
			  $(RESOURCES) \
			  $(METADATA) \
			  $(HELPERS) \
			  $(DTD) \
			  $(XSL) \
			  $(RESRNG)

rasdir			= ${CLUSTERDATA}

ras_SCRIPTS		= $(TARGET) \
			  $(RESOURCES) \
			  $(HELPERS)

ras_DATA		= $(METADATA)

rngdir			= ${CLUSTERDATA}/relaxng

rng_DATA		= $(DTD) $(XSL) $(RESRNG)

$(TARGET):
	cat $(abs_srcdir)/$@.in | sed \
		-e 's#@''LOGDIR@#${LOGDIR}#g' \
	> $@.out
	chmod +x $@.out
	mv $@.out $@

clean-local:
	rm -f $(TARGET) resources.rng

ras-validation: $(RESOURCES) $(TARGET) $(DTD)
	@echo Validating resource agent meta-data
	@for f in $(RESOURCES); do \
		echo "   $(abs_srcdir)/$$f "; \
		bash $(abs_srcdir)/$$f meta-data | xmllint --dtdvalid \
			$(abs_srcdir)/$(DTD) --noout -; \
		if [ $$? -ne 0 ]; then exit 1; fi \
	done
	@for f in $(TARGET); do \
		echo "   $(abs_builddir)/$$f "; \
		bash $(abs_builddir)/$$f  meta-data | xmllint --dtdvalid \
			$(abs_srcdir)/$(DTD) --noout -; \
		if [ $$? -ne 0 ]; then exit 1; fi \
	done

#
# Schema maintenance.  Run 'make resources.rng' and paste it in to
# config/tools/xml/cluster.rng.in where it says 'autogenerated'.
#
# resources.rng.* should never be distributed by themselves.
#
resources.rng: $(RESOURCES) $(TARGET) utils/config-utils.sh
resources.rng: $(XSL) $(RESRNG)
	rm -f resources.rng
	cat resources.rng.head >> resources.rng
	@echo Generating per-resource RelaxNG information...
	@for f in $(RESOURCES) $(TARGET); do \
		echo "    ./$$f"; \
		bash ./$$f meta-data | xsltproc ra2rng.xsl - >> resources.rng; \
	done
	cat resources.rng.mid >> resources.rng
	@echo Generating per-resource RelaxNG reference information...
	@for f in $(RESOURCES) $(TARGET); do \
		echo "    ./$$f"; \
		bash ./$$f meta-data | xsltproc ra2ref.xsl - >> resources.rng; \
	done
	cat resources.rng.tail >> resources.rng

utils/config-utils.sh:
	make -C utils config-utils.sh
